/*
 * Copyright (c) 2008 VMware, Inc.
 * Copyright (c) 2009 John Pritchard, WTKX Project Group
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package wtkx;

import wtkx.util.ListenerList;
import wtkx.wtk.TooltipListener;

/**
 * Window representing a "tooltip". Tooltips are used to provide additional
 * context information to a user. A tooltip generally appears after a certain
 * amount of time has passed and closes when the user moves the mouse.
 *
 * @author gbrown
 */
public class Tooltip 
    extends Window 
{

    public static class TooltipListenerList
        extends ListenerList<TooltipListener>
        implements TooltipListener 
    {
        TooltipListenerList(){
            super();
        }

        public void textChanged(Tooltip tooltip, String previousText) {
            for (TooltipListener listener : this) {
                listener.textChanged(tooltip, previousText);
            }
        }
    }


    private String text = null;

    private TooltipListenerList tooltipListeners = new TooltipListenerList();


    public Tooltip(String text) {
        super();
        this.setText(text);
        this.installSkin(Tooltip.class);
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        String previousText = this.text;

        if (previousText != text) {
            this.text = text;
            tooltipListeners.textChanged(this, previousText);
        }
    }

    /**
     * @return
     * <tt>true</tt>; by default, tooltips are auxilliary windows.
     */
    @Override
    public boolean isAuxilliary() {
        return true;
    }

    public ListenerList<TooltipListener> getTooltipListeners() {
        return tooltipListeners;
    }
}
